package com.icinema.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;

public class UserComfirmServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8517143455662785881L;

	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
	throws Exception {
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();		
		String userKey = request.getParameter("selected");
		Entity user = datastore.get(KeyFactory.stringToKey(userKey));
		
		if(user != null){
			user.setProperty("status","A");
			datastore.put(user);
			response.setContentType("text/html");
			response.getWriter().write("Thank you for confirmation. Now you can <a href='http://i-cinema.appspot.com'>login</a> to the application");
		}
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			processRequest(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			processRequest(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
